package com.hzvdvmc.autosale.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzvdvmc.autosale.R;
import com.hzvdvmc.autosale.common.OnItemClickListener;
import com.hzvdvmc.autosale.constant.SpKey;

public class ActionbarActivity extends BaseActivity {
    ImageView ivBack;
    Toolbar toolbar;
    TextView tvTitle, tvFunc;

    public void setCustomeActiorBar(String title) {
        try {
            toolbar = (Toolbar) findViewById(R.id.toolbar);
            ivBack = (ImageView) findViewById(R.id.iv_back);
            setSupportActionBar(toolbar);
            if (getSupportActionBar() != null) {
                getSupportActionBar().setHomeButtonEnabled(true);
//                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                getSupportActionBar().setDisplayShowTitleEnabled(false);
            }
            if (!TextUtils.isEmpty(title)) {
                tvTitle = (TextView) findViewById(R.id.tv_title);
                tvTitle.setText(title);
            }
            ivBack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setHomeButtonEnabled(boolean enabled) {
        if (getSupportActionBar() != null) {
            getSupportActionBar().setHomeButtonEnabled(enabled);
        }
    }

    public void setRightFuncBtn(String name, View.OnClickListener onClickListener) {
        try {
            tvFunc = (TextView) findViewById(R.id.tv_func);
            tvFunc.setVisibility(View.VISIBLE);
            tvFunc.setText(name);
            tvFunc.setOnClickListener(onClickListener);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean onSupportNavigateUp() {
        finish();
        return super.onSupportNavigateUp();
    }
}
